package com.example.soss.entity;

import lombok.Data;

@Data
public class Page {
    private Integer currentPage = 1;
    private Integer limit = 7;
    private Integer totalSize;
    private String path;

    public Integer getFrom() {
        if (currentPage > 3) {
            int res = currentPage;
            while (res > 1) --res;
            return res;
        }

        if (currentPage - 2 < 1) return 1;
        return currentPage - 2;
    }

    public Integer getTo() {
        if (currentPage < 3) {
            int res = 3;
            while (res < getTotalPage() && res < 6) ++res;
            return res;
        }
        if (currentPage + 2 > getTotalPage()) return getTotalPage();
        return currentPage + 2;

    }

    public Integer getTotalPage() {
        if (totalSize % limit == 0) return totalSize / limit;
        return totalSize / limit + 1;
    }

    public Integer getOffset() {
        return limit * currentPage - limit;
    }
}
